package com.ssyan.factory.factorymethod.order;


import com.ssyan.factory.factorymethod.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author ssyan
 * @Description 使用工厂方法模式
 * @create 2021/8/27 23:20
 * @Version 1.0
 */
public abstract class OrderPizza {

    String orderType;

    //构造器
    public OrderPizza() {
        while (true) {
            orderType = getType();
            Pizza pizza = createPizza(orderType);//抽象方法，由工厂子类完成
            //输出pizza制作过程
            //输出pizza
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            }else {
                System.out.println("订购披萨失败");
                break;
            }
        }
    }

    //定义一个抽象方法,createPizza,让各个工厂子类自己实现
    abstract Pizza createPizza(String orderType);

    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
